package dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;
import java.util.Vector;

import model.*;
import util.ConnectDataBase;

public class ReservationDAO  {
	Vector listreservation;
	ConnectDataBase connectDataBase;

	public ReservationDAO() {
		listreservation = new Vector();
		connectDataBase= new ConnectDataBase();
	}

	public Vector getListreservation() {
		try {
			ResultSet rs = connectDataBase
					.query_select("Select * from Reservation");

			while (rs.next()) {

				int reservation_id = Integer.parseInt(rs
						.getString("reservation_id"));
				int customer_id = Integer.parseInt(rs.getString("customer_id"));
				int room_id = Integer.parseInt(rs.getString("room_id"));
				Date expected_arrive_date = rs.getDate("expected_arrive_date");
				Date expected_departure_date = rs
						.getDate("expected_departure_date");

				int status = rs.getInt("status");
				String note = rs.getString("note");
				int employee_check_in = rs.getInt("employee_check_in");
				int employee_check_out = rs.getInt("employee_check_out");
				int employee_reservation = rs.getInt("employee_reservation");

				Reservation re = new Reservation(reservation_id, customer_id,
						room_id, expected_arrive_date, expected_departure_date,
						status, note, employee_check_in, employee_check_out,
						employee_reservation);
				listreservation.add(re);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return listreservation;
	}

	public void insert_reservation(Reservation re) {

		String sql = "Insert into Reservation(customer_id,room_id,expected_arrive_date,expected_departure_date,status,employee_reservation) values("
				+ re.getCustomer_id()
				+ ","
				+ re.getRoom_id()
				+ ",'"
				+ re.getExpected_arrive_date()
				+ "','"
				+ re.getExpected_departure_date()
				+ "',"
				+ re.getStatus()
				+ ","
				+ re.getEmployee_reservation() + ")";

		connectDataBase.query_update(sql);
		
	}
}
